import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 收藏信息 */
export interface Collection {
  id: number // 收藏唯一ID
  userId: number // 用户ID
  bookId: number // 书籍ID
  creator: string // 创建者
  createTime: string | Dayjs // 创建时间
  updater: string // 更新者
  updateTime: string | Dayjs // 更新时间
  deleted: boolean // 是否删除
}

// 收藏 API
export const CollectionApi = {
  // 查询收藏分页
  getCollectionPage: async (params: any) => {
    console.log('**************************', params)
    return await request.get({ url: `/pickbook/collection/page`, params })
  },

  // 查询收藏详情
  getCollection: async (id: number) => {
    return await request.get({ url: `/pickbook/collection/get?id=` + id })
  },

  // 新增收藏
  createCollection: async (data: Collection) => {
    return await request.post({ url: `/pickbook/collection/create`, data })
  },

  // 修改收藏
  updateCollection: async (data: Collection) => {
    return await request.put({ url: `/pickbook/collection/update`, data })
  },

  // 删除收藏
  deleteCollection: async (id: number) => {
    return await request.delete({ url: `/pickbook/collection/delete?id=` + id })
  },

  /** 批量删除收藏 */
  deleteCollectionList: async (ids: number[]) => {
    return await request.delete({ url: `/pickbook/collection/delete-list?ids=${ids.join(',')}` })
  },

  // 导出收藏 Excel
  exportCollection: async (params) => {
    return await request.download({ url: `/pickbook/collection/export-excel`, params })
  }
}
